package com.app.view.component.dialogs.pkResultView 
{
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.display.Loader;
	
	import com.peachcastle.core.Display;
	
	import com.app.model.data.UserData;
	import com.app.view.component.resource.ResourceManager;
	
	/**
	 * ...
	 * @author kevin
	 */
	public class UserInfo extends Display
	{
		private var _txt_name:TextField = null;
		
		private var _avatar:MovieClip = null;
		
		public function UserInfo(ui:MovieClip = null) 
		{
			super(ui);
		}
		
		override protected function initialization():void 
		{
			super.initialization();
			
			_txt_name = assest["txt_name"];
			_avatar = assest["avatar"];
		}	
		
		public function show(data:UserData):void
		{
			_txt_name.text = data.name;
			updateAvatar(data);
		}
		
		private function updateAvatar(data:UserData):void
		{
			if (_avatar.numChildren > 1) _avatar.removeChildAt(1);
		
			var loader:Loader = ResourceManager.getInstance().getObjectLoader(data.mid, "pk");
			
			if (loader)
			{
				_avatar.addChild(loader);
			}else
			{
				loader = ResourceManager.getInstance().addObjectLoader(data.mid, "pk", data.icon, 72, 1);
				_avatar.addChild(loader);
			}
		}
	}

}